import 'package:FineArt/core/http/base_dio.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart';
import '../../constants.dart';

part 'course_api.g.dart';

@RestApi(baseUrl: kBaseUrl)
abstract class CourseApi {
  factory CourseApi({Dio dio, String baseUrl}) {
    dio ??= BaseDio.getInstance().getDio();
    return _CourseApi(dio, baseUrl: baseUrl);
  }

  @PUT("/api/v1/course/{id}") //操作控制命令
  Future<OperationResponse> operate(
      @Path("id") int courseid, @Body() SimpleOperation oper);

  @DELETE("/api/v1/course") //删除教学
  Future<OperationResponse> delete();

  @GET("/api/v1/course/{id}") // 获取指定id教学会话的详情。
  Future<CourseInfoResponse> courseInfo(@Path("id") int courseId);
}

////////////
@JsonSerializable()
class OperationResponse {
  int code;
  OperationResult result;

  OperationResponse({this.code, this.result});

  factory OperationResponse.fromJson(Map<String, dynamic> json) =>
      _$OperationResponseFromJson(json);
}

@JsonSerializable()
class OperationResult {
  String message;

  OperationResult({this.message});

  factory OperationResult.fromJson(Map<String, dynamic> json) =>
      _$OperationResultFromJson(json);
}

@JsonSerializable()
class Operation {
  // 操作指令，up,down,left,right,rotate,zoomin,zoomout,layout,gray，turn(翻页）,cicle(环拍转动),...
  String oper;

  // 对应操作指令的值，如果是几何运动，则采用相对移动值，按照百分比，而不是绝对像素，主要考虑不通屏幕的适配。
  String value;

  String Reserve;

  int Step;

  Operation({this.oper, this.value, this.Reserve, this.Step});

  Map<String, dynamic> toJson() => _$OperationToJson(this);

  factory Operation.fromJson(Map<String, dynamic> json) =>
      _$OperationFromJson(json);
}

@JsonSerializable()
class SimpleOperation {
  // 操作指令，up,down,left,right,rotate,zoomin,zoomout,layout,gray，turn(翻页）,cicle(环拍转动),...
  String oper;

  // 对应操作指令的值，如果是几何运动，则采用相对移动值，按照百分比，而不是绝对像素，主要考虑不通屏幕的适配。
  String value;

  SimpleOperation({this.oper, this.value});

  Map<String, dynamic> toJson() => _$SimpleOperationToJson(this);

  factory SimpleOperation.fromJson(Map<String, dynamic> json) =>
      _$SimpleOperationFromJson(json);
}

////////////
/////////////
@JsonSerializable()
class CourseInfoResponse {
  int code;
  String requestId;
  String msg;
  CourseInfo data;

  CourseInfoResponse({this.code, this.data, this.msg, this.requestId});

  factory CourseInfoResponse.fromJson(Map<String, dynamic> json) =>
      _$CourseInfoResponseFromJson(json);
}

@JsonSerializable()
class CourseInfo {
  int Id; // 教学会话id
  int AssetId; // 课件资源id
  int Layout; // 显示的版式
  List<String> Members;
  int Step;
  List<Operation> Opers; // 所有操作指令的最后状态数组,按照这个状态描述恢复当前资源
  int SubItem;

  CourseInfo(
      {this.Id,
      this.AssetId,
      this.Layout,
      this.Members,
      this.Step,
      this.Opers,
      this.SubItem});

  factory CourseInfo.fromJson(Map<String, dynamic> json) =>
      _$CourseInfoFromJson(json);
}
/////////////
